Remove xstrappend (#878)
authorGPSBabel <12013583+GPSBabelDeveloper@users.noreply.github.com>
Mon, 23 May 2022 21:24:55 +0000 (16:24 -0500)
committerGitHub <noreply@github.com>
Mon, 23 May 2022 21:24:55 +0000 (16:24 -0500)
* PDF maker: format screen and input same. Shrink padding slightly.

* Use reference counted pointers instead of managing our own.
Fixes a leak when using debug printing.

* Remove the last remaining caller of xstrappend and thus, that c-era utility.

Co-authored-by: Robert Lipe <robertlipe@users.noreply.github.com>
defs.h
garmin_gpi.cc
garmin_txt.cc
util.cc

diff --git a/defs.h b/defs.h
index 99ea2945b0995699fe6e0d669a9640c226d0e456..8e8e698ee53d87911629b6d366fc1ceb83d1c54e 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -1037,7 +1037,6 @@ void* xrealloc(void* p, size_t s);
 void xfree(const void* mem);
 char* xstrdup(const QString& s);
 char* xstrndup(const char* str, size_t sz);
-char* xstrappend(char* src, const char* newd);
 char* xstrdup(const char* s);
 
 FILE* xfopen(const char* fname, const char* type, const char* errtxt);
index 57a08a65b4065e8dd89aa01f16e0ff3954613c58..696c62d27bb3a23c971ef5f0da89ec61deba0993 100644 (file)
@@ -562,11 +562,11 @@ GarminGPIFormat::read_tag(const char* caller, const int tag, Waypoint* wpt)
       gbfread(b.get(), 1, sz, fin);
       fprintf(stderr, "\n");
       for (x = 0; x < sz; x++) {
-       fprintf(stderr, "%02x ", b[x]);
+       fprintf(stderr, "%02x ", b[x]);
       }
       fprintf(stderr, "\n");
       for (x = 0; x < sz; x++) {
-       fprintf(stderr, "%c", isalnum(b[x]) ? b[x] : '.');
+       fprintf(stderr, "%c", isalnum(b[x]) ? b[x] : '.');
       }
       fprintf(stderr, "\n");
     }
index 32c0d560063ec988a8168bd4996127157aa0f551..6b0fcd0a3209fe131504c3d5535a7eeacc129df5 100644 (file)
@@ -186,15 +186,19 @@ get_option_val(const char* option, const char* def)
 static void
 init_date_and_time_format()
 {
-  const char* f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT);
-  date_time_format = convert_human_date_format(f);
+  // This is old, and weird, code.. date_time_format is a global that's
+  // explicitly malloced and freed elsewhere. This isn't very C++ at all,
+  // but this format is on its deathbead for deprecation.
+  const char* d = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT);
+  char* d1 = convert_human_date_format(d);
 
-  date_time_format = xstrappend(date_time_format, " ");
+  const char* t = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT);
+  char* t1 = convert_human_time_format(t);
 
-  f = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT);
-  const char* c = convert_human_time_format(f);
-  date_time_format = xstrappend(date_time_format, c);
-  xfree((void*) c);
+  xasprintf(&date_time_format, "%s %s", d1, t1);
+
+  xfree(d1);
+  xfree(t1);
 }
 
 static void
diff --git a/util.cc b/util.cc
index 9007b68e77a74c2386c9b220e45caa65621ec49d..a1d9d9a2ec49cf904eff01634f98b7f83804f56c 100644 (file)
--- a/util.cc
+++ b/util.cc
@@ -139,26 +139,6 @@ xrealloc(void* p, size_t s)
   return o;
 }
 
-/*
-* For an allocated string, realloc it and append 's'
-*/
-char*
-xstrappend(char* src, const char* newd)
-{
-  if (!src) {
-    return xstrdup(newd);
-  }
-  if (!newd) {
-    return xstrdup(src);
-  }
-
-  size_t newsz = strlen(src) + strlen(newd) + 1;
-  src = (char*) xrealloc(src, newsz);
-  strcat(src, newd);
-
-  return src;
-}
-
 /*
  * Wrapper for open that honours - for stdin, stdout, unifies error text.
  */